﻿namespace SampleApp.Tests.Pages {
    using Microsoft.Services.TestTools.UITesting.Html;
    using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;

    [EntryUri("/Products/Create")]
    public class ProductsCreate : Page {

        public Products CreateNewProduct(string productName, string price) {
            Browser.SetEditTexts(new {
                                         Name      = productName,
                                         UnitPrice = price
                                     });
            Browser.Check("InStock");
            Browser.Select("CategoryId", itemIndex: 1);
            Browser.ClickOnButton("Create");

            return NavigatedTo<Products>();;
        }

        public bool ValidationMessageIsDisplayedForField(string fieldName) {
            var span = Browser.Find<HtmlSpan>("data-valmsg-for", fieldName);
            return (span.Exists && !(string.IsNullOrEmpty(span.InnerText)));
        }
    }
}